const { chromium } = require('playwright');
const { login, getHours, delay, browserArgs } = require('./utils');

module.exports = async ({ urls }) => {
  const browser = await chromium.launch({
    // headless: false,
    args: browserArgs,
  });
  const context = await browser.newContext();
  const page = await context.newPage();

  await login(page);

  let total = 0;
  const data = [];
  for (const url of urls) {
    const result = await getHours(page, url);
    if (result) {
      total += result.hours;
      data.push(result);
    }
    await delay(500);
  }

  await browser.close();

  return {
    total,
    data,
  };
};
